package com.hzeport.bgs22emduty.service.impl;

import com.hzeport.bgs22emduty.config.SystemConfig;
import com.hzeport.bgs22emduty.dto.WebSocketSendInfoDTO;
import com.hzeport.bgs22emduty.service.WebSocketSendInfoServer;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.*;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;

import javax.annotation.Resource;

@Service
@Slf4j
public class WebSocketSendInfoServerImpl implements WebSocketSendInfoServer {

    @Resource
    private SystemConfig systemConfig;

    RestTemplate restTemplate=new RestTemplate();

    @Override
    public void sendAll(WebSocketSendInfoDTO webSocketSendInfoDTO) {
        HttpHeaders headers=new HttpHeaders();
        headers.setContentType(MediaType.APPLICATION_JSON);
        HttpEntity<WebSocketSendInfoDTO> entity=new HttpEntity<>(webSocketSendInfoDTO,headers);
        restTemplate.exchange(systemConfig.getWebSocketSendInfoUrl()+"/sendAll", HttpMethod.POST, entity, String.class);
    }

    @Override
    public void sendAllHZ(WebSocketSendInfoDTO webSocketSendInfoDTO) {
        HttpHeaders headers=new HttpHeaders();
        headers.setContentType(MediaType.APPLICATION_JSON);
        HttpEntity<WebSocketSendInfoDTO> entity=new HttpEntity<>(webSocketSendInfoDTO,headers);
        restTemplate.exchange(systemConfig.getWebSocketSendInfoUrl()+"/sendAllHZ", HttpMethod.POST, entity, String.class);
    }

    @Override
    public void sendAllZS(WebSocketSendInfoDTO webSocketSendInfoDTO) {
        HttpHeaders headers=new HttpHeaders();
        headers.setContentType(MediaType.APPLICATION_JSON);
        HttpEntity<WebSocketSendInfoDTO> entity=new HttpEntity<>(webSocketSendInfoDTO,headers);
        restTemplate.exchange(systemConfig.getWebSocketSendInfoUrl()+"/sendAllZS", HttpMethod.POST, entity, String.class);
    }

    @Override
    public void sendAllDistribute(WebSocketSendInfoDTO webSocketSendInfoDTO) {
        HttpHeaders headers=new HttpHeaders();
        headers.setContentType(MediaType.APPLICATION_JSON);
        HttpEntity<WebSocketSendInfoDTO> entity=new HttpEntity<>(webSocketSendInfoDTO,headers);
        restTemplate.exchange(systemConfig.getWebSocketSendInfoUrl()+"/sendAllDistribute", HttpMethod.POST, entity, String.class);
    }
}
